package com.desaysv.wandroid;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

import com.desaysv.svhttp.callback.IRequestCallBack;
import com.desaysv.wandroid.entity.BaseRes;
import com.desaysv.wandroid.http.HttpManager;
import com.desaysv.svnotice.MessageBlockQueue;

import java.util.Map;

/**
 * @author linzi
 * @date 2022-12-1
 */
public class TestService extends Service {
    private static final String TAG = "[TestService]";

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Log.e(TAG, "onCreate: ");
        MessageBlockQueue.getInstance().notify(new Stub(1));

        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 500; i++) {
                    test(i);
                }
            }
        }).start();

    }

    public void test(int num) {
        HttpManager.INSTANCE.getService().getTopAirtics(new IRequestCallBack<BaseRes>() {
            @Override
            public void response(int status, Map headers, BaseRes o) {
                Log.i(TAG, "response: " + num + ";code===" + status);
            }

            @Override
            public void start() {

            }

            @Override
            public void error(Throwable error) {

            }

            @Override
            public void complete() {

            }
        });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.e(TAG, "onDestroy: ");
        MessageBlockQueue.getInstance().notify(new Stub(0));
    }

    public static class Stub {
        Stub(int status) {
            this.status = status;
        }

        private int status;

        public int getStatus() {
            return status;
        }
    }
}
